﻿@model Shop.Areas.Admin.Models.ModelUpdateCategories

@{
    ViewBag.Title = "UpdateCategories";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>UpdateCategories</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>ModelUpdateCategories</legend>

        <div class="editor-field">
            @Html.HiddenFor(model => model.IdProduct)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Categories)
        </div>
        <div class="editor-field">

            @foreach (var cat in ViewBag.Categories)
            {
                if (Model.Categories.Where(i => i.Id == cat.Id).Count() != 0)
                {
                    @Html.CheckBox("idCategories", true, new { value = @cat.Id }) @cat.Name
                }
                else
                {
                    @Html.CheckBox("idCategories", false, new { value = @cat.Id }) @cat.Name
                }
            }

            @Html.ValidationMessageFor(model => model.Categories)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
